package com.example.cloudprinter.printer.feie.format;

import com.example.cloudprinter.printer.IFormat;

/**
 * 飞鹅打印机指令格式
 */
public class FeieFormat implements IFormat {

    /**
     * 内容居中
     *
     * @param content
     * @return
     */
    @Override
    public String center(String content) {
        return "<C>" + content + "</C>";
    }

    /**
     * 内容居左
     *
     * @param content
     * @return
     */
    @Override
    public String left(String content) {
        return content;
    }

    /**
     * 内容居右
     *
     * @param content
     * @return
     */
    @Override
    public String right(String content) {
        return "<RIGHT>" + content + "</RIGHT>";
    }

    /**
     * 字体加粗
     *
     * @param content
     * @return
     */
    @Override
    public String bold(String content) {
        return "<BOLD>" + content + "</BOLD>";
    }

    /**
     * 字体加大
     *
     * @param content
     * @return
     */
    @Override
    public String big(String content) {
        return "<B>" + content + "</B>";
    }

    /**
     * 1行3列
     *
     * @param colunm1
     * @param colunm2
     * @param colunm3
     * @param isChinese 是否全是中文
     * @return
     */
    @Override
    public String threeColunm(String colunm1, String colunm2, String colunm3, boolean isChinese) {
        String content = "";
        if (colunm1.length() > 6) {//第1列内容太长需要换行
            content += colunm1.substring(0, 6);
        } else {
            content += colunm1;
        }

        if (colunm1.length() > 6) {
            int length1 = isChinese ? 16 - colunm1.length() * 2 - 2 : 16 - 12 - 1;
            for (int i = 1; i <= length1; i++)
                content += " ";
        } else {
            int length2 = isChinese ? 16 - colunm1.length() * 2 - 2 : 16 - colunm1.length() * 2 - 1;
            for (int i = 1; i <= length2; i++)
                content += " ";
        }
        content += colunm2;

        int length3 = isChinese ? 16 - colunm2.length() * 2 - colunm3.length() * 2 + 1 : 16 - colunm2.length() - colunm3.length();
        for (int i = 1; i <= length3; i++)
            content += " ";

        content += colunm3;

        if (colunm1.length() > 6) {
            content += colunm1.substring(6) + "<BR>";
        } else {
            content += "<BR>";
        }
        return content;
    }

    /**
     * 换行
     *
     * @param lines 行数
     * @return
     */
    @Override
    public String newline(int lines) {
        String content = "";
        for (int i = 0; i < lines; i++)
            content += "<BR>";
        return content;
    }
}
